<?php

/**
 * This is the model class for table "tbl_users".
 *
 * The followings are the available columns in table 'tbl_users':
 * @property string $user_id
 * @property string $user_name
 * @property string $user_eng_name
 * @property string $format_date
 * @property string $format_time
 * @property string $language
 * @property string $password
 * @property string $insert_user_id
 * @property string $insert_user_ip
 * @property string $insert_date
 * @property string $update_user_id
 * @property string $update_user_ip
 * @property string $update_date
 * @property string $status
 * @property string $avatar
 *
 * The followings are the available model relations:
 * @property TblMenuUsers[] $tblMenuUsers
 * @property TblComnCode $status0
 * @property TblFileAttachGrp $avatar0
 */
class User extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_users';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('user_id, user_name, user_eng_name, format_date, format_time, language, password, insert_user_id, insert_user_ip, insert_date, update_user_id, update_user_ip, update_date', 'required'),
			array('user_id, user_name, user_eng_name, insert_user_id, insert_user_ip, update_user_id, update_user_ip', 'length', 'max'=>50),
			array('format_date, format_time', 'length', 'max'=>15),
			array('language', 'length', 'max'=>2),
			array('password', 'length', 'max'=>100),
			array('status', 'length', 'max'=>10),
			array('avatar', 'length', 'max'=>20),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('user_id, user_name, user_eng_name, format_date, format_time, language, password, insert_user_id, insert_user_ip, insert_date, update_user_id, update_user_ip, update_date, status, avatar', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'tblMenuUsers' => array(self::HAS_MANY, 'TblMenuUsers', 'user_id'),
			'status' => array(self::BELONGS_TO, 'TblComnCode', 'status'),
			'avatar' => array(self::BELONGS_TO, 'TblFileAttachGrp', 'avatar'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'user_id' => 'User',
			'user_name' => 'User Name',
			'user_eng_name' => 'User Eng Name',
			'format_date' => 'Format Date',
			'format_time' => 'Format Time',
			'language' => 'Language',
			'password' => 'Password',
			'insert_user_id' => 'Insert User',
			'insert_user_ip' => 'Insert User Ip',
			'insert_date' => 'Insert Date',
			'update_user_id' => 'Update User',
			'update_user_ip' => 'Update User Ip',
			'update_date' => 'Update Date',
			'status' => 'Status',
			'avatar' => 'Avatar',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('user_id',$this->user_id,true);
		$criteria->compare('user_name',$this->user_name,true);
		$criteria->compare('user_eng_name',$this->user_eng_name,true);
		$criteria->compare('format_date',$this->format_date,true);
		$criteria->compare('format_time',$this->format_time,true);
		$criteria->compare('language',$this->language,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('insert_user_id',$this->insert_user_id,true);
		$criteria->compare('insert_user_ip',$this->insert_user_ip,true);
		$criteria->compare('insert_date',$this->insert_date,true);
		$criteria->compare('update_user_id',$this->update_user_id,true);
		$criteria->compare('update_user_ip',$this->update_user_ip,true);
		$criteria->compare('update_date',$this->update_date,true);
		$criteria->compare('status',$this->status,true);
		$criteria->compare('avatar',$this->avatar,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return User the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
